package unipd.esp1112.pro;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


/**
 * Activity to select the desired training method
 * 
 * @author andrea basso, federico lancerin, alex tomasello
 * 
 */
public class SelezioneAttivita extends Activity {

	/**
	 * auxiliary variable called from another activity to kill this one and go directly back to the main menu
	 */
	public static boolean daTerminare = false;
	/**
	 * button to select a training limited by time
	 */
	private Button tempo;
	/**
	 * button to select a training limited by distance
	 */
	private Button distanza;
	/**
	 * button to select a training limited by calories
	 */
	private Button calorie;
	/**
	 * button to select free training ( no limits )
	 */
	private Button libero;
	/**
	 * button to select a custom training
	 */
	private Button suMisura;
	/**
	 * variable to store the name of the profile the user is currently using
	 */
	private String nomeProfilo;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activityselection);

		Intent intent = getIntent();
		nomeProfilo = intent.getStringExtra("profilo");

		tempo = (Button) findViewById(R.id.tempoLimite);
		tempo.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), ImpostaParametri.class);
				myIntent.putExtra("attivita", "tempo");
				myIntent.putExtra("profilo", nomeProfilo);
				startActivityForResult(myIntent, 0);
			}
		});

		distanza = (Button) findViewById(R.id.distanzaLimite);
		distanza.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), ImpostaParametri.class);
				myIntent.putExtra("attivita", "distanza");
				myIntent.putExtra("profilo", nomeProfilo);
				startActivityForResult(myIntent, 0);
			}
		});

		calorie = (Button) findViewById(R.id.calorieLimite);
		calorie.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), ImpostaParametri.class);
				myIntent.putExtra("attivita", "calorie");
				myIntent.putExtra("profilo", nomeProfilo);
				startActivityForResult(myIntent, 0);
			}
		});

		libero = (Button) findViewById(R.id.Libero);
		libero.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), Misurazioni.class);
				myIntent.putExtra("attivita", "libero");
				myIntent.putExtra("profilo", nomeProfilo);
				startActivityForResult(myIntent, 0);
			}
		});

		suMisura = (Button) findViewById(R.id.suMisura);
		suMisura.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), SuMisura.class);
				myIntent.putExtra("profilo", nomeProfilo);
				startActivityForResult(myIntent, 0);
			}
		});
	}

	protected void onResume() {
		super.onResume();
		if (daTerminare) {
			daTerminare = false;
			System.out.println("Menu terminato");
			finish();
		}
	}

}
